//
//  UserTableViewCell.m
//  Travel
//
//  Created by 吴品泽 on 15/4/11.
//  Copyright (c) 2015年 &#21556;&#21697;&#27901;. All rights reserved.
//

#import "UserTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <UIButton+WebCache.h>
@implementation UserTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.traImageView = [[UIImageView alloc]init];
        self.titleLabel = [[UILabel alloc]init];
        self.timerLabel = [[UILabel alloc]init];
        self.userButton = [[UIButton alloc]init];
        self.backView = [[UIView alloc]init];
        [self.contentView addSubview:self.traImageView];
        [self.traImageView addSubview:self.backView];
        [self.traImageView addSubview:self.titleLabel];
        [self.traImageView addSubview:self.timerLabel];
        [self.traImageView addSubview:self.userButton];
        
    }
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.traImageView.frame = CGRectMake(10, 5, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 5);
    self.traImageView.userInteractionEnabled = YES;
    self.backView.frame = self.traImageView.bounds;
    self.backView.backgroundColor = [UIColor blackColor];
    self.backView.alpha = 0.2;
    
#warning cell中内容高度不一的自适应高度
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:19] };
    // self.traImageView.backgroundColor = [UIColor blackColor];
    self.titleLabel.numberOfLines = 0;
    NSString *string = self.notes.name;
    
    // NSLog(@"wwwwww%@",string);
    CGRect rect = [string boundingRectWithSize:CGSizeMake(self.traImageView.frame.size.width - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    // NSLog(@"%f",rect.size.height);
    self.titleLabel.font = [UIFont boldSystemFontOfSize:19];
    self.titleLabel.frame = CGRectMake(10, 10, self.traImageView.frame.size.width - 20, rect.size.height);
    self.titleLabel.textColor = [UIColor whiteColor];
    //self.titleLabel.backgroundColor = [UIColor yellowColor];
    
    self.timerLabel.frame = CGRectMake(10, 10 + rect.size.height , self.traImageView.frame.size.width - 20, 20);
    
    self.userButton.frame = CGRectMake(10, self.traImageView.frame.size.height - 60, 50, 50);
    //self.userButton.backgroundColor = [UIColor redColor];
    self.userButton.layer.masksToBounds = YES;
    self.userButton.layer.cornerRadius = 25;
    
//    NSString *imagstr =  [self.notes.user objectForKey:@"image"];
//    NSURL *urls = [NSURL URLWithString:imagstr];
//    
//#warning 占位图没加（用户图片）
//    [self.userButton sd_setBackgroundImageWithURL:urls forState:UIControlStateNormal placeholderImage:nil];
//    
//    [self.userButton addTarget:self.targetAction action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
    //self.userButton.backgroundColor = [UIColor redColor];
    //self.timerLabel.backgroundColor = [UIColor purpleColor];
    
    //赋值
    self.titleLabel.text = self.notes.name;
    if ([self.notes.name isEqualToString:@"雪国列车"]) {
        NSString *str = [NSString stringWithFormat:@" %@天 / %@图",self.notes.days,self.notes.photos_count];
        self.timerLabel.font = [UIFont systemFontOfSize:14];
        self.timerLabel.textColor = [UIColor whiteColor];
        self.timerLabel.alpha = 0.8;
        self.timerLabel.text = str;
    }else{
        NSString *str = [NSString stringWithFormat:@"%@ / %@天 / %@图",self.notes.start_date,self.notes.days,self.notes.photos_count];
        self.timerLabel.font = [UIFont systemFontOfSize:14];
        self.timerLabel.textColor = [UIColor whiteColor];
        self.timerLabel.alpha = 0.8;
        self.timerLabel.text = str;
    }
    
    
    
    NSURL *url = [NSURL URLWithString:self.notes.front_cover_photo_url];
    
    
    
#warning 占位图还没有添加
    [self.traImageView sd_setImageWithURL:url placeholderImage:nil];
    
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
